<style scoped lang="less">

</style>
<template>
	<Upload action="/api/admin/Oss/uploadFile"
	        :on-success="handleSuccess"
	        :on-error="handleError"
	        :show-upload-list="true"
	        :headers="headers"
	        :format="format"
	        :on-format-error="handleFormatError"
	        :on-exceeded-size="handleMaxSize"
	        :on-remove="handleRemove"
	        :before-upload="handleBeforeUpload"
	        :max-size="maxSize">
		<Button icon="ios-cloud-upload-outline">Upload files</Button>
	</Upload>
</template>
<script>
  import {getToken} from '@/libs/util'
	export default {
    name:'file-upload',
		data(){
      return{
        params: null,
        headers: null,
      }
		},
    props: {
      countLimit: {type: Number, default: -1},
      format: {type: Array, default: function () {
          return []
        }},
      maxSize: {type: Number, default: null},
    },
		created(){
      this.headers = {'apiAuth': getToken()};
		},
		methods:{
      handleFormatError (file) {
        this.$Notice.warning({
          title: '格式错误',
          desc: file.name + ' 格式错误, 请选择视频,如 mp4/avi/flv等.'
        });
      },
      handleSuccess (res, file,filelist) {
        debugger
        this.$emit('on-flies-change', this.filelist);
      },
      handleBeforeUpload (res, file,filelist) {
        debugger
        this.$emit('on-flies-change', this.filelist);
      },
      handleRemove (file, filelist) {
        this.formItem.video = res.data.url;
      },
      handleError (res, file) {
        // 上传失败
        this.$Notice.warning({
          title: '上传失败',
          desc: file.name + ' 上传失败.'
        });
        this.formItem.video = res.data.url;
      },
      handleMaxSize (file) {
        this.$Notice.warning({
          title: '超过文件大小限制',
          desc: '文件最大不超过 2M.'
        });
      },
		}
	}
</script>